package net.bithappens.hnqe.impl.querymanager;

import java.util.Collection;

import net.bithappens.hnqe.mapper.IMapper;
import net.bithappens.hnqe.query.QueryTree;

import org.apache.log4j.Logger;

public class LazyLoadHandler {

	private Logger log = Logger.getLogger(this.getClass());
	
	public LazyLoadHandler() {}

	public boolean triggerLazyLoad(String instanceId, Collection<IMapper> listToTrigger, QueryTree query) {
		
		//TODO:Opimize Query here
		boolean reloadRequired = false;
		for(IMapper mapper : listToTrigger){
			log.info("fetch: "+mapper.getMapperId());
			reloadRequired |= mapper.fetch(instanceId, query);
		}
		
		log.info("reload state: "+reloadRequired);
		
		return reloadRequired;
	}
}
